package com.XinYun.Library.modules.display.controller;


import com.XinYun.Library.modules.display.entity.book;
import com.XinYun.Library.modules.display.response.ResponseWrapper;
import com.XinYun.Library.utils.SqlUtils.DruidUtil;
import com.XinYun.Library.modules.display.dao.sqlexecutor;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;





public class displayImpl implements display {

    @Override
    public List<book> getALL(String sql,String value)throws SQLException, IOException {
        //处理返回结果
        ResultSet resultSet = sqlexecutor.select(sql,value);
        book books = null;
        List<book> bookList = new ArrayList<>();
        try{
            //resultSet.next()：判断返回结果是否有值
            while (resultSet.next()){
                books = new book();
                //获取数据库表的内容
                books.setBookname(resultSet.getString("bookname"));
                books.setNum(resultSet.getInt("num"));
                books.setLoan(resultSet.getInt("loan"));
                books.setLike(resultSet.getInt("like"));
                //列入集合
                bookList.add(books);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //关闭资源
            DruidUtil.close(resultSet);
        }

        return bookList;
    }
}
